package com.wuseguang.springcloud.service.impl;

import com.wuseguang.springcloud.dao.jdbc.EvaluationLabelJdbc;
import com.wuseguang.springcloud.dao.repository.EvaluationLabelRepository;
import com.wuseguang.springcloud.entity.EvaluationLabel;
import com.wuseguang.springcloud.service.EvaluationLabelService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 学校评价标签表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-02-02
 */
@Service
public class EvaluationLabelServiceImpl  implements EvaluationLabelService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private EvaluationLabelJdbc evaluationLabelJdbc;
    @Autowired
    private EvaluationLabelRepository evaluationLabelRepository;

    @Override
    public Result addEvaluationLabel(EvaluationLabel evaluationLabel) {

        logger.info("添加标签 EvaluationLabelServiceImpl -> addEvaluationLabel ");
        //获取id
        int id =evaluationLabelRepository.save(evaluationLabel).getId();
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        return new Result(map);
    }

    @Override
    public Result findEvaluationLabel(String schoolId) {
        logger.info("查询标签 EvaluationLabelServiceImpl -> findEvaluationLabel ");
        //查询学校的标签
        String sql = "select id,name from evaluation_label where school_id= ?";

        List<Map<String,Object>> list = evaluationLabelJdbc.queryListMap(sql,schoolId);
        return new Result(list);
    }

    @Override
    public Result deleteEvaluationLabel(Integer id) {
        evaluationLabelRepository.deleteById(id);
        //根据评价标签删除评价信息
        String sql = "DELETE FROM `evaluation_label_and_score_item` WHERE `evaluation_label_id` = ?";
        //删除
        evaluationLabelJdbc.updateByParameter(sql,id);

        return new Result();
    }
}
